package io.renren.modules.picApproval.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import io.renren.modules.picApproval.entity.MediaFileEntity;
import io.renren.modules.picApproval.service.MediaFileService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.picApproval.entity.ShootEntity;
import io.renren.modules.picApproval.service.ShootService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;


/**
 * 
 * 
 * @author wxy
 * @email sharonwang_xy@163.com
 * @date 2018-10-26 15:30:06
 */
@RestController
@RequestMapping("picApproval/shoot")
public class ShootController {
	@Autowired
	private ShootService shootService;

	@Autowired
	private MediaFileService mediaFileService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("picApproval:shoot:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<ShootEntity> shootList = shootService.queryList(query);
		int total = shootService.queryList(query.noLimit()).size();
		
		PageUtils pageUtil = new PageUtils(shootList, total, query.getLimit(), query.getCurrPage());
		
		return R.ok().put("page", pageUtil);
	}


	/**
	 * 图片审批
	 */
	@RequestMapping("/process")
	@RequiresPermissions("picApproval:shoot:process")
    public R picProcess(@RequestBody Map<String, String> params){


        String shootId = params.get("shootId");
        String processStatus = params.get("processStatus");

	    ShootEntity shootProcessEntity = new ShootEntity();
        shootProcessEntity.setShootId(shootId);
        shootProcessEntity.setProcessStatus(processStatus);
        shootProcessEntity.setCheckTime(new Date());

        MediaFileEntity mediaProcessEntity = new MediaFileEntity();
        mediaProcessEntity.setShootId(shootId);
        mediaProcessEntity.setProcessStatus(processStatus);

        System.out.print("shootProcess-------------"+shootProcessEntity.toString());
        System.out.print("mediaProcess-------------"+mediaProcessEntity.toString());

        shootService.shootProcess(shootProcessEntity);
        mediaFileService.mediaProcess(mediaProcessEntity);

		return  R.ok();
	}

	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{shootId}")
	@RequiresPermissions("picApproval:shoot:info")
	public R info(@PathVariable("shootId") String shootId){
		ShootEntity shoot = shootService.queryObject(shootId);
		
		return R.ok().put("shoot", shoot);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("picApproval:shoot:save")
	public R save(@RequestBody ShootEntity shoot){
		shootService.save(shoot);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("picApproval:shoot:update")
	public R update(@RequestBody ShootEntity shoot){
		shootService.update(shoot);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("picApproval:shoot:delete")
	public R delete(@RequestBody String[] shootIds){
		shootService.deleteBatch(shootIds);
		
		return R.ok();
	}
	
}
